package com.bwlcums.preview;

import java.io.File;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bwlcums.preview.service.FileListPreviewService;
import com.bwlcums.preview.service.FileListPreviewServiceImpl;
import com.bwlcums.utils.FileUtils;
import com.bwlcums.utils.StringUtils;

@WebServlet(value = "/fileListPreview")
public class FileListPreview extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String webRootPath = FileUtils.getWebRootPath();
		File f = new File(webRootPath);
		req.setAttribute("webRootPath", f.getAbsolutePath());
		
		FileListPreviewService service = new FileListPreviewServiceImpl();

		req.setAttribute("filecount", service.getAllFileNum());
		req.setAttribute("filesize", StringUtils.convertFileSize(service.getAllFileLength()));
		req.setAttribute("fileList", service.getFilesInfoDataList());
		
		req.getRequestDispatcher("/preview/fileListPage.jsp").forward(req, resp);
	}
	
}
